<template>
  <!-- 方案规划导航栏 -->
   <div style="width: 100%;height: 100%;text-align: center;">
  
    <div style="display: flex;margin-top: 1vh;" class="box">
 
      <el-form :inline="true" :model="formInline" style="margin-left: 1vh;margin-top: 0.5vh;width: 80%;text-align: left;" class="demo-form-inline">
        <el-form-item label="方案名称:">
          <el-input style="width: 90%;margin-top: 0vh;" v-model="schemeName">
          </el-input>
        </el-form-item>

        <el-form-item label="计算状态:">
          
          <el-select v-model="calculationStatus" placeholder="请选择">
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>

        </el-form-item>

      </el-form>

      <div id="buttonDiv" style="text-align: right;margin-top: 0.7vh;width: 19%;">
        
        <el-button type="primary" @click="queryPageData()" style="width: 110px">
          <span class="button-text">查询</span>
        </el-button>
 
      </div>

       
    </div>

    <div>

      <el-table :data="tableData" border height="590" style="width: 99%;margin: 1vh auto;">
        <el-table-column prop="schemeName" align="center" label="方案名称"></el-table-column>
        <el-table-column prop="createTime"  align="center"  label="创建时间"></el-table-column>
        <el-table-column prop="calculationStatusLabel"  align="center"  label="计算状态"></el-table-column>
        <el-table-column prop="calculationStartTime"  align="center"  label="计算开始时间"></el-table-column>
        <el-table-column prop="calculationEndTime"  align="center"  label="计算结束时间"></el-table-column>
        <el-table-column prop="calculationTime"  align="center"  label="计算耗时"></el-table-column>

        <el-table-column
          fixed="right"
          label="操作"
          align="center" 
          width="150">
          <template slot-scope="scope">
            <el-link @click="executeAlgorithm(scope.row)" style="color: #409EFF;" type="text" size="small">计算</el-link>
            <el-link @click="suspendCalculat(scope.row)" v-if="scope.row.calculationStatus=='1'" style="color: #409EFF;" type="text" size="small">中止计算</el-link>
          </template>
        </el-table-column>

        <el-table-column
          fixed="right"
          label="计算结果展示"
          align="center" 
          width="240">
          <template slot-scope="scope">
            <el-link @click="showPage(scope.row,'heConfigurationPlan')" type="text" style="color: #409EFF;" size="small">配置方案</el-link>
            <el-link @click="showPage(scope.row,'heCostBreakdown')" type="text" style="color: #409EFF;" size="small">成本明细</el-link>
            <el-link @click="showPage(scope.row,'operationCharacteristics')" type="text" style="color: #409EFF;" size="small">运行特性</el-link>
          </template>
        </el-table-column>

      </el-table>

    </div>
 

</div>
  
</template>

<script>
 

  export default {
    name: 'heAnalogComputation',
    data() {
      return {
        schemeName : '',
        calculationStatus : "",
        projectId : '',
        options: [{
          value: '0',
          label: '未计算'
        }, {
          value: '1',
          label: '计算中'
        }, {
          value: '2',
          label: '已完成'
        }],
        tableData:[],
        activeDate: '',
        buttonText: '运行', 
        source : "",
        
      }
    },
    mounted: function() {
      this.projectId = this.$route.query.projectId;
      this.queryPageData();
    },
    methods: {

      suspendCalculat: function(row){
        var vm = this;
        var schemeId = row.schemeId; 
        this.$http.post('/iepsapi/ea/algorithm/suspendCalculat?id='+schemeId+"&tableName=he_scheme_selection"+"&algorithmType=he").then((res) => {
          vm.queryPageData();
        }).catch((error) => {
          console.log(error);
        });

      },

      queryPageData : function(){

        var vm = this; 

        this.$http.post('/iepsapi/ea/algorithm/querySchemeInfo?schemeName='+this.schemeName+"&tableName=he_scheme_selection"+"&calculationStatus="+this.calculationStatus+"&projectId="+this.projectId).then((res) => {
          var result = res.data.data;
          
          vm.tableData = result;
          
        }).catch((error) => {
          console.log(error);
        });


      }, 

      showPage : function(row,pageName){

        var schemeId = row.schemeId;

        if(row.calculationStatus == "2"){

          this.$parent.schemeId = schemeId;

          if(pageName=="heConfigurationPlan"){
            this.$parent.buttonClick('heConfigurationPlan', 'heDiv5');
          }else if(pageName=="heCostBreakdown"){
            this.$parent.buttonClick('heCostBreakdown', 'heDiv6');
          }else if(pageName=="operationCharacteristics"){
            this.$parent.buttonClick('operationCharacteristics', 'heDiv7');
          }

        }else{
          this.$message({
            type: 'info',
            message: '该方案暂未计算或正在计算中，请选择计算完成的方案查询结果!'
          });
          return;
        }

      },
      
      executeAlgorithm : function(row){

        
        var schemeId = row.schemeId;

        var tableData = this.tableData;

        for(var i=0;i<tableData.length;i++){
          if(tableData[i].calculationStatus == "1"){
            this.$message({
              type: 'info',
              message: '当前已有方案正在计算当中，请完成计算后再执行该操作!'
            });
            return;
          }
        }
        
        var vm = this;
        
  
        if(row.calculationStatus == "2"){

          this.$confirm('是否重新继续该方案数据?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {

            const loading = this.$loading({
              lock: true,
              text: '调用算法中',
              spinner: 'el-icon-loading',
              background: 'rgba(0, 0, 0, 0.7)'
            });
            
            this.$http.post('/iepsapi/ea/algorithm/executeAlgorithmEnergyHydrogen?schemeId='+schemeId+"&projectId="+this.projectId).then((res) => {
              var result = res.data;
              if(result.resultFlag == "success"){
                
                loading.close();

                this.$message({
                  type: 'success',
                  message: '执行成功!'
                });

                vm.queryPageData();

              }else{
                this.$message({
                  type: 'info',
                  message: result.message
                });
              }
            }).catch((error) => {
              console.log(error);
            });

          }).catch(() => {
            this.$message({
              type: 'info',
              message: '已取消操作'
            });          
          });


        }else if(row.calculationStatus == "0"){

          
            const loading = this.$loading({
              lock: true,
              text: '调用算法中',
              spinner: 'el-icon-loading',
              background: 'rgba(0, 0, 0, 0.7)'
            });

            this.$http.post('/iepsapi/ea/algorithm/executeAlgorithmEnergyHydrogen?schemeId='+schemeId+"&projectId="+this.projectId).then((res) => {
              var result = res.data;
              if(result.resultFlag == "success"){
                
                loading.close();

                this.$message({
                  type: 'success',
                  message: '执行成功!'
                });

                vm.queryPageData();

              }else{
                this.$message({
                  type: 'info',
                  message: result.message
                });
              }
            }).catch((error) => {
              console.log(error);
            });


        }


      }
       
    }
  }
</script>



<style>

.el-table__body tr.hover-row.current-row>td, .el-table__body tr.hover-row.el-table__row--striped.current-row>td, .el-table__body tr.hover-row.el-table__row--striped>td, .el-table__body tr.hover-row>td
{
  background: #14265D;
}
 

.el-table__empty-text {
    line-height: 60px;
    width: 50%;
    color: #ffffff;
}

.el-table td, .el-table th {
    padding: 12px 0;
    min-width: 0;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
    text-overflow: ellipsis;
    vertical-align: middle;
    position: relative;
    text-align: left;
    color: #ffffff;
    background: #14265D;
}

.el-table__empty-block {
    background: #14224e;
    min-height: 60px;
    text-align: center;
    width: 100%;
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-pack: center;
    -ms-flex-pack: center;
    justify-content: center;
    -webkit-box-align: center;
    -ms-flex-align: center;
    align-items: center;
}


.el-table{
  background-color: rgb(20 34 78);
  color: #FFFFFF;
  border-color: rgb(24 63 124 / 51%);
  *{
    border-color: rgb(24 63 124 / 51%) !important;
  }
  .el-table__header-wrapper{
    tr{
      background-color: rgb(10 24 90 / 81%);
      th{
        color: #ffffff;
        background-color: rgba(0,0,0,0.4);
      }
    }
  }
  .el-table__body-wrapper{
    tr{
      background-color: rgb(8 26 80 / 88%);
      &:hover>td{      
        background-color: rgb(13 30 80);
      }
    }
  }
}
  .el-form--inline .el-form-item__content {
      display: inline-block;
      vertical-align: middle;
      margin-left: 1vh;
  }

  .el-radio {
      color: #eff4ff;
      cursor: pointer;
      margin-right: 30px;
  }

  .el-form-item {
      margin-bottom: 5px;
  }
  .el-form-item__label {
      text-align: right;
      vertical-align: middle;
      float: left;
      font-size: 14px;
      color: #f2f2f2;
      line-height: 40px;
      padding: 0 1px 0 0;
      -webkit-box-sizing: border-box;
      box-sizing: border-box;
  }
  .el-input__inner { 
      background-color: #202b6180;
      background-image: none;
      border-radius: 4px;
      border: 1px solid #5c7bc5;
      -webkit-box-sizing: border-box;
      box-sizing: border-box;
      color: #a3aec5;
      display: inline-block;
      font-size: inherit;
      height: 40px;
      line-height: 40px;
      outline: 0;
      padding: 0 15px;
      -webkit-transition: border-color .2s cubic-bezier(.645,.045,.355,1);
      transition: border-color .2s cubic-bezier(.645,.045,.355,1);
      width: 100%;
  }

  .el-input-group__append, .el-input-group__prepend {
    background-color: #305997;
    color: #ffffff;
    vertical-align: middle;
    display: table-cell;
    position: relative;
    border: 1px solid #506aa7;
    border-radius: 4px;
    padding: 0 20px;
    width: 1px;
    white-space: nowrap;
  }
</style>


<style scoped> 

/deep/.el-table th, .el-table tr {
    background-color: #111941;
    color: #ffffff; 
}

/deep/.el-input.is-disabled .el-input__inner {
    background-color: #0e2c58e3;
    border-color: #E4E7ED;
    color: #C0C4CC;
    cursor: not-allowed;
}


  /* 设定地图的大小 */
  #allmap{
    height: 350px;
    width: 100%;
  }

  .buttonStyle {
    height: 4vh;
    width: 27vh;
    display: inline-block;
    -webkit-border-radius: 60px;
    -moz-border-radius: 60px;
    cursor: pointer;
    border-radius: 10px;
    font-family: Arial;
    border: none;
    color: #ffffff;
    font-size: 1.6vh;
    background: #1f2c6c3b;
    border-bottom: 1px solid rgb(64, 158, 255);
    margin: 1.5vh 10px;
    text-align: center;
    line-height: 4vh;
    vertical-align: middle;
    text-decoration: none;
  }

  .box{ 
    width: 98%;
    height: 6vh;
    margin: auto;
    border-radius: 5px;
    margin: auto;
    /* background: #202b614f;
    border: 1px solid rgb(62 111 219 / 88%); */
  }

  .titleCss{
    font-size: 22px;
    font-family: inherit;
    font-weight: 500;
    line-height: 1.2;
    color: #f2f2f2;
  }
</style>
